//    The page gives admin the functionality to set minimum bidding amount per speciality        
//    The data will be inserted/updated to the tbl_speciality.                                
//    Author: Rupinder Saini                                                                    
//    Date: May 15,2006 

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
using System.Data.SqlClient;

public partial class Admin_SetBidding : System.Web.UI.Page
{// creating an instance of manager class
    Manager mgr = new Manager(true,"ConnectionString");
    int id = 0;
       
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            id = Convert.ToInt32(Request.QueryString["id"]);
        }
        catch { id = 0; }
        
        if (!Page.IsPostBack)
    {
        // check page validation and load the page contents if edit  mode
        Page.Validate();
        loadcontents();
    }
    }


    /// <summary>
    /// add bid for the speciality
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_submit_Click(object sender, EventArgs e)
    {
        check_validations();
        if (Page.IsValid)
        {
            if (Convert.ToInt32(ddlSpeciality.SelectedItem.Value.ToString()) > 0)
            {
                try
                {
                    SqlParameter[] sqlParam = new SqlParameter[2];
                    sqlParam[0] = new SqlParameter("@Spec_id", SqlDbType.Int);
                    sqlParam[1] = new SqlParameter("@amt", SqlDbType.Decimal);
                    sqlParam[1].Precision = 18;
                    sqlParam[1].Scale = 2;
                    sqlParam[0].Value = ddlSpeciality.SelectedItem.Value;
                    sqlParam[1].Value = txt_bid.Text;
                    mgr.ExecuteUpdate("insert_specialitybid", sqlParam);
                    lblMsg.Visible = true;
                    lblMsg.ForeColor = System.Drawing.Color.Green;
                    lblMsg.Text = "Minimum Bid set successfully";
                    mgr.ClearFields(Page, "0");
                }
                catch (Exception es)
                {
                    lblMsg.Visible = true;
                    lblMsg.ForeColor = System.Drawing.Color.Red;
                    lblMsg.Text = es.ToString();
                }
            }
            else
            {
                lbl_errspe.Visible = true;
            }
        }
    }

     #region generalfunctions
    /// <summary>
    /// check validations
    /// </summary>
    public void check_validations()
    {
        rval_bid.Enabled = true;
        rval_bid.Validate();
    }


    /// <summary>
    /// pre-fill  controls if edit mode 
    /// </summary>
    public void loadcontents()
    {
        mgr.BindList("select id,name from tbl_speciality", "name", "id", ddlSpeciality, "select");
        if (id > 0)
        {
            DataSet ds = mgr.ExecuteQuery("select id,name,MinBid from tbl_speciality where id=" + id, "tbl");
            if (ds.Tables[0].Rows.Count > 0)
            {
                txt_bid.Text = ds.Tables[0].Rows[0]["MinBid"].ToString();
                ddlSpeciality.SelectedValue = ds.Tables[0].Rows[0]["id"].ToString();
            }
        }
    }
     #endregion

}
